﻿using System;
using System.ComponentModel;
using System.Linq;
using System.Xml.Serialization;
using Microsoft.WowAddonStudio.FrameXml.Serialization.Enumerations;

namespace Microsoft.WowAddonStudio.FrameXml.Serialization.LayoutFrames
{
    [Serializable]
    [DesignerCategory("code")]
    [XmlType(Namespace = "http://www.blizzard.com/wow/ui/")]
    [XmlRoot(Namespace = "http://www.blizzard.com/wow/ui/", IsNullable = false)]
    public class Slider : Frame
    {
        /// <summary>
        /// Gets or sets the draw layer to be used by the status bar. The default value is overlay.
        /// </summary>
        [XmlAttribute("drawLayer")]
        [Category("Behavior")]
        [DefaultValue(DrawLayer.Overlay)]
        [Description("Defines the draw layer to be used by the status bar. The default value is overlay.")]
        public DrawLayer DrawLayer
        {
            get { return Properties.GetValue<DrawLayer>("DrawLayer"); }
            set { Properties.SetValue("DrawLayer", value); }
        }

        /// <summary>
        /// Gets or sets the minimum value of the status bar.
        /// </summary>
        [XmlAttribute("minValue")]
        [Category("Behavior")]
        [Description("Defines the lowest numeric value a slider will accept.")]
        public float MinValue
        {
            get { return Properties.GetValue<float>("MinValue"); }
            set { Properties.SetValue("MinValue", value); }
        }

        /// <summary>
        /// Gets or sets a value indicating whether the <see cref="MinValue"/> is specified. This property is not serialized.
        /// </summary>
        [XmlIgnore]
        [Browsable(false)]
        public bool MinValueSpecified
        {
            get { return Properties.HasValue("MinValue"); }
        }

        /// <summary>
        /// Gets or sets the maximum value of the status bar.
        /// </summary>
        [XmlAttribute("maxValue")]
        [Category("Behavior")]
        [Description("Defines the highest numeric value a slider will accept.")]
        public float MaxValue
        {
            get { return Properties.GetValue<float>("MaxValue"); }
            set { Properties.SetValue("MaxValue", value); }
        }

        /// <summary>
        /// Gets or sets a value indicating whether the <see cref="MaxValue"/> is specified. This property is not serialized.
        /// </summary>
        [XmlIgnore]
        [Browsable(false)]
        public bool MaxValueSpecified
        {
            get { return Properties.HasValue("MaxValue"); }
        }

        /// <summary>
        /// Gets or sets the default value of the status bar.
        /// </summary>
        [XmlAttribute("defaultValue")]
        [Category("Behavior")]
        [Description("The DefaultValue property specifies the default value for the control.")]
        public float DefaultValue
        {
            get { return Properties.GetValue<float>("DefaultValue"); }
            set { Properties.SetValue("DefaultValue", value); }
        }

        /// <summary>
        /// Gets or sets a value indicating whether the <see cref="DefaultValue"/> is specified. This property is not serialized.
        /// </summary>
        [XmlIgnore]
        [Browsable(false)]
        public bool DefaultValueSpecified
        {
            get { return Properties.HasValue("DefaultValue"); }
        }

        /// <summary>
        /// Gets or sets the value step of the status bar.
        /// </summary>
        [XmlAttribute("valueStep")]
        [Category("Behavior")]
        [Description("Tells a slider how far to jump per click.")]
        public float ValueStep
        {
            get { return Properties.GetValue<float>("ValueStep"); }
            set { Properties.SetValue("ValueStep", value); }
        }

        /// <summary>
        /// Gets or sets a value indicating whether the <see cref="ValueStep"/> is specified. This property is not serialized.
        /// </summary>
        [XmlIgnore]
        [Browsable(false)]
        public bool ValueStepSpecified
        {
            get { return Properties.HasValue("ValueStep"); }
        }

        /// <summary>
        /// Gets or sets the orientation of the status bar. The default value is vertical.
        /// </summary>
        [XmlAttribute("orientation")]
        [DefaultValue(Orientation.Vertical)]
        [Category("Behavior")]
        [Description("Defines the orientation of the status bar. The default value is vertical.")]
        public Orientation Orientation
        {
            get { return Properties.GetValue<Orientation>("Orientation"); }
            set { Properties.SetValue("Orientation", value); }
        }

        /// <summary>
        /// Gets or sets the texture used for the slider's thumb.
        /// </summary>
        [XmlElement]
        [Category("Appearance")]
        [Description("Defines the texture used for the slider's thumb.")]
        public Texture ThumbTexture
        {
            get { return Properties.GetValue<Texture>("ThumbTexture"); }
            set { Properties.SetValue("ThumbTexture", value); }
        }

        /// <summary>
        /// Gets a value indicating whether a serialization object is complete and can be rendered.
        /// </summary>
        public override bool IsComplete
        {
            get
            {
                return this.Layers.SelectMany(layer => layer.Items)
                           .OfType<Texture>()
                           .Count() > 0;
            }
        }
    }
}